package com.my;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
 * Created by YJH on 2017/7/13 22:09.
 */
public class HelloServletContextListener implements ServletContextListener, ServletRequestListener, HttpSessionListener {

    private final String TAG = getClass().getSimpleName();

    /**
     * ServletContext对象被创建（即，当前WEB应用被加载时）的时候，Servlet容器调用该方法.
     */
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        System.out.println(TAG + "--->context创建--->" + servletContextEvent.getServletContext());
    }

    /**
     * ServletContext对象被销毁之前（即，当前WEB应用被卸载之前）的时候，Servelet容器调用该方法.
     */
    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        System.out.println(TAG + "--->context销毁--->" + servletContextEvent.getServletContext());
    }

    @Override
    public void requestInitialized(ServletRequestEvent servletRequestEvent) {
        System.out.println(TAG+"--->request创建");
    }

    @Override
    public void requestDestroyed(ServletRequestEvent servletRequestEvent) {
        System.out.println(TAG+"--->request销毁");
    }

    @Override
    public void sessionCreated(HttpSessionEvent httpSessionEvent) {
        System.out.println(TAG+"--->session创建");
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
        System.out.println(TAG+"--->session销毁");
    }
}
